package org.lex.ftplist.ui.common;

import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.Box;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.lex.ftplist.core.FtpUrl;

public class OpenFtpPane extends JPanel {
	private JButton okButton;
	private JButton cancelButton;
	private JComboBox historyComboBox;
	private JLabel historyLabel;
	private JPanel buttonsPane;
	private FtpUrlPane ftpUrlPane;

	public OpenFtpPane() {
		initComponents();
	}

	public FtpUrl getUrl() {
		return ftpUrlPane.getUrl();
	}

	public JButton getOkButton() {
		return okButton;
	}

	public JButton getCancelButton() {
		return cancelButton;
	}

	private void initComponents() {
		setLayout(new GridBagLayout());

		GridBagConstraints gc;
		// history label & combobox
		historyLabel = new JLabel("History");
		gc = new GridBagConstraints();
		gc.gridx = 0;
		gc.gridy = 0;
		gc.anchor = GridBagConstraints.WEST;
		gc.insets = new Insets(12, 12, 11, 6);
		add(historyLabel, gc);

		historyComboBox = new JComboBox();
		historyComboBox.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
		gc = new GridBagConstraints();
		gc.gridx = 1;
		gc.gridy = 0;
		gc.fill = GridBagConstraints.HORIZONTAL;
		gc.weightx = 1.0;
		gc.insets = new Insets(12, 0, 11, 11);
		add(historyComboBox, gc);

		// ftpurlpane
		ftpUrlPane = new FtpUrlPane();
		gc = new GridBagConstraints();
		gc.gridx = 0;
		gc.gridy = 1;
		gc.gridwidth = 2;
		gc.fill = GridBagConstraints.HORIZONTAL;
		gc.weightx = 1.0;
		gc.insets = new Insets(0, 12, 11, 11);
		add(ftpUrlPane, gc);
		// glue
		Component glue = Box.createGlue();
		gc = new GridBagConstraints();
		gc.gridx = 0;
		gc.gridy = 2;
		gc.gridwidth = GridBagConstraints.REMAINDER;
		gc.gridheight = 1;
		gc.weightx = 100;
		gc.weighty = 100;
		gc.fill = GridBagConstraints.BOTH;
		add(glue, gc);
		// buttons
		FlowLayout flowLayout = new FlowLayout(FlowLayout.RIGHT, 5, 5);
		flowLayout.setAlignOnBaseline(true);
		buttonsPane = new JPanel(flowLayout);

		okButton = new JButton("OK");
		buttonsPane.add(okButton);

		cancelButton = new JButton("Cancel");
		buttonsPane.add(cancelButton);

		gc = new GridBagConstraints();
		gc.gridx = 0;
		gc.gridy = GridBagConstraints.RELATIVE;
		gc.gridwidth = GridBagConstraints.REMAINDER;
		gc.weightx = 1;
		gc.fill = GridBagConstraints.HORIZONTAL;
		gc.insets = new Insets(0, 12, 0, 11);
		add(buttonsPane, gc);
	}
}
